package com.ruoyi.ams.controller;

import com.ruoyi.ams.domain.AmsAssetTag;
import com.ruoyi.ams.service.IAmsAssetTagService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 资产标签信息Controller
 *
 * @author yfkj
 * @date 2021-10-15
 */
@RestController
@RequestMapping("/ams/AmsAssetTag")
public class AmsAssetTagController extends BaseController {
    @Autowired
    private IAmsAssetTagService amsAssetTagService;

    /**
     * 查询资产标签信息列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsAssetTag:list")
    @GetMapping("/list")
    public TableDataInfo list(AmsAssetTag amsAssetTag) {
        startPage();
        List<AmsAssetTag> list = amsAssetTagService.selectAmsAssetTagList(amsAssetTag);
        return getDataTable(list);
    }

    /**
     * 导出资产标签信息列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsAssetTag:export")
    @Log(title = "资产标签信息", businessType = BusinessType.EXPORT)
    @PostMapping(value="/export", produces = "application/octet-stream")
    public void export(HttpServletResponse response, AmsAssetTag amsAssetTag) throws IOException {
        List<AmsAssetTag> list = amsAssetTagService.selectAmsAssetTagList(amsAssetTag);
        ExcelUtil<AmsAssetTag> util = new ExcelUtil<AmsAssetTag>(AmsAssetTag.class);
        util.exportExcel(response, list, "资产标签信息数据");
    }

    /**
     * 获取资产标签信息详细信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsAssetTag:query")
    @GetMapping(value = "/{assetTagId}")
    public AjaxResult getInfo(@PathVariable("assetTagId") Long assetTagId) {
        return AjaxResult.success(amsAssetTagService.selectAmsAssetTagByAssetTagId(assetTagId));
    }

    /**
     * 新增资产标签信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsAssetTag:add")
    @Log(title = "资产标签信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AmsAssetTag amsAssetTag) {
        return toAjax(amsAssetTagService.insertAmsAssetTag(amsAssetTag));
    }

    /**
     * 修改资产标签信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsAssetTag:edit")
    @Log(title = "资产标签信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AmsAssetTag amsAssetTag) {
        return toAjax(amsAssetTagService.updateAmsAssetTag(amsAssetTag));
    }

    /**
     * 删除资产标签信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsAssetTag:remove")
    @Log(title = "资产标签信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{assetTagIds}")
    public AjaxResult remove(@PathVariable Long[] assetTagIds) {
        return toAjax(amsAssetTagService.deleteAmsAssetTagByAssetTagIds(assetTagIds));
    }
}
